<template>
	<view class="main">
		<view class="box-bg">
			<Icon icon="bytesize:reply"
				style="color: black;font-size: 40rpx; position:  relative; left: 30rpx;top: 20rpx;" @click="back()" />
			<uni-search-bar placeholder="手机号/昵称" :focus="true" v-model="keyword" bgColor="white"
				style="position: relative;bottom: 10rpx;left: 30rpx;width: 600rpx;" @input="search" />
		</view>

		<view class="userList">

			<list v-for="i in userList" :key="i.id"> <!---->
				<view class="userBox">
					<view class="userAvatar">
						<image class="userAvatar" :fade-show="true" mode="aspectFill" :src=i.avatar>
						</image>
					</view>
					<view class="userName">
						<view>{{i.name}}</view>
						<view style="display: flex;color: #099cf3;">(<view style="color:black ;">{{i.phone}}</view>)
						</view>

					</view>
					<view class="bot">
						<button class="bot" type="default" size="mini" @click="add(i.id)">添加</button>
					</view>
				</view>
			</list>

		</view>
		<uni-popup ref="popup" background-color="#fff" type="bottom">
			<view class="popup-content">
				<text class="text">popup 内容</text>
			</view>
		</uni-popup>
		<view>

		</view>
	</view>
</template>

<script setup lang="ts">
	import { onMounted, ref, nextTick, type Ref } from 'vue'
	import { Icon } from '@iconify/vue';
	import { request } from '@/api/request';
	import type { AccountDto } from '@/api/model/account/AccountDto';
	const keyword = ref('')
	const userList : Ref<AccountDto[]> = ref([]);

	const back = () => {
		uni.navigateBack({
			delta: 1
		})
	}

	const search = () => {
		nextTick(async () => {
			const data = { keyword: keyword.value }
			const operation = {
				method: 'get',
				url: `/main/account/search`,
				data: data,
				tokenRequired: true // 新增，表示是否需要token
			};
			const res = await request(operation);
			userList.value = res.data.account
			console.log(JSON.stringify(userList.value))
		})
	}

	const add = async (id : string) => {

		const operation = {
			method: 'post',
			url: `/main/apply/create/${id}`,
			data: '',
			tokenRequired: true // 新增，表示是否需要token
		};
		const res = await request(operation);
		console.log(res)
	}
	/* 控制弹出层
	const popup = ref(null)
	const open = () => {
	   popup.value.open('bottom') 
	} */
</script>

<style lang="scss">
	.main {
		.box-bg {
			margin-top: 60rpx;
			display: flex;
		}

		display: flex;
		flex-direction: column;
		height: 100vh;
		background-color: #eeedf2;
	}

	.userList {
		display: flex;
		flex-direction: column;
		height: auto;
		background-color: #eeedf2;

		.userBox {
			display: flex;
			position: relative;
			width: auto;
			height: 140rpx;
			background-color: white;
			border-radius: 15rpx;
			margin-top: 20rpx;
			margin-left: 20rpx;
			margin-right: 20rpx;

			.userName {
				display: flex;
				flex-direction: row;
				margin-top: 50rpx;
				position: relative;
				margin-left: 25rpx;
				height: 50rpx;
				width: 400rpx;
			}

			.userAvatar {
				margin-top: 10rpx;
				margin-left: 15rpx;
				width: 100rpx;
				height: 100rpx;
				border-radius: 50%;
				padding-left: 30 rpx;
			}

			.bot {
				background-color: white;
				margin-top: 20rpx;
				border-color: #cccccc;
			}
		}
	}

	.popup-content {
		align-items: center;
		justify-content: center;
		margin-top: 1000rpx;
		padding: 15px;
		height: 100vh;
		background-color: #fff;
	}
</style>